﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameJam2012
{
    public class DeathEntity : Entity
    {

        public DeathEntity(int x, int y)
            : base()
        {
            Position.X = x * SnakeGame.TILESIZE;
            Position.Y = y * SnakeGame.TILESIZE;
        }

        public override FloatRectangle GetBoundingBox()
        {
            return new FloatRectangle(Position.X, Position.Y, SnakeGame.TILESIZE, SnakeGame.TILESIZE);
        }

        public override void Kill()
        {

        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, float xOffset, float yOffset, Microsoft.Xna.Framework.Color tint)
        {
            //spriteBatch.Draw(SnakeGame.WHITETILE, Position + new Microsoft.Xna.Framework.Vector2(xOffset, yOffset), null, Microsoft.Xna.Framework.Color.Red, 0f, Vector2.Zero, 1f, SpriteEffects.None, .5f);
            base.Draw(spriteBatch, xOffset, yOffset, tint);
        }
    }

    public class Spike : Entity
    {
        public Spike(int x, int y)
            : base()
        {
            Position.X = x * SnakeGame.TILESIZE;
            Position.Y = y * SnakeGame.TILESIZE;
            sprite = SnakeGame.SPIKETILES[SnakeGame.Random.Next(SnakeGame.SPIKETILES.Count)];
        }

        public override FloatRectangle GetBoundingBox()
        {
            return new FloatRectangle(Position.X, Position.Y, SnakeGame.TILESIZE, SnakeGame.TILESIZE);
        }

        public override void Kill()
        {

        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, float xOffset, float yOffset, Microsoft.Xna.Framework.Color tint)
        {
            spriteBatch.Draw(sprite, Position + new Microsoft.Xna.Framework.Vector2(xOffset, yOffset), null, tint, 0f, Vector2.Zero, 1f, SpriteEffects.None, .5f);
            base.Draw(spriteBatch, xOffset, yOffset, tint);
        }
    }

    public class SawBlade : Entity
    {
        float rotation = 0f;
        float rotationSpeed = -.05f;

        public SawBlade(int x, int y)
            : base()
        {
            Position.X = x * SnakeGame.TILESIZE + SnakeGame.TILESIZE / 2;
            Position.Y = y * SnakeGame.TILESIZE + SnakeGame.TILESIZE / 2;
            sprite = SnakeGame.SAWBLADE;
            rotation = (float)SnakeGame.Random.NextDouble();
            rotationSpeed = rotationSpeed * (float)SnakeGame.Random.NextDouble() / 2 + rotationSpeed;
        }

        public override void Update(GameTime gameTime, Level level)
        {
            base.Update(gameTime, level);
            rotation += rotationSpeed;
        }

        public override FloatRectangle GetBoundingBox()
        {
            return new FloatRectangle(Position.X - 32, Position.Y - 32, SnakeGame.TILESIZE, SnakeGame.TILESIZE);
        }

        public override void Kill()
        {

        }

        public override void CollideWith(Entity e)
        {
            if (e is PlayerEntity)
                sprite = SnakeGame.SAWBLADEBLOODY;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, float xOffset, float yOffset, Microsoft.Xna.Framework.Color tint)
        {
            spriteBatch.Draw(sprite, Position + new Microsoft.Xna.Framework.Vector2(xOffset, yOffset), null, tint,rotation, new Vector2(32,32), 1f, SpriteEffects.None, .5f);
            base.Draw(spriteBatch, xOffset, yOffset, tint);
        }
    }
}
